package com.jiamao.goplay.ui.user.vm;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;

import com.jiamao.goplay.bean.PaifItme;
import com.jiamao.goplay.ui.discover.SearchFragment;
import com.jiamao.goplay.ui.discover.vm.AddrDetailVM;
import com.jiamao.goplay.ui.user.OthersUserInfoFragment;
import com.netease.nim.uikit.api.NimUIKit;

import androidx.databinding.ObservableField;
import androidx.databinding.ObservableInt;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;

public class UserPaifItemVM extends MultiItemViewModel {

    public ObservableField<String> imgUrl = new ObservableField<>("");
    public ObservableField<String> name = new ObservableField<>("");
    public ObservableField<String> statusDes = new ObservableField<>("");
    public ObservableField<String> userDes = new ObservableField<>("");

    public ObservableInt ypdBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yyqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt yqBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt jsyqBtnVisibility = new ObservableInt(View.GONE);

    public ObservableInt jcpdBtnVisibility = new ObservableInt(View.GONE);
    public ObservableInt scyqBtnVisibility = new ObservableInt(View.GONE);


    public ObservableField<Integer> isVip = new ObservableField<>();
    public ObservableField<Integer> isShming = new ObservableField<>();
    public ObservableField<Integer> isRenXiang = new ObservableField<>();



    private String uid,id;
    public UserPaifItemVM(@NonNull BaseViewModel viewModel, PaifItme itme) {
        super(viewModel);
        if (itme ==null){
            return;
        }
        id = itme.getId();
        uid = itme.getUid();
        imgUrl.set(itme.getAvatar());
        name.set(itme.getNickname());
        String sex = itme.getGender() == 1 ?"他":"她";
        String userDesStr =  sex+"邀请我去："+itme.getPlaceName();
        if (itme.getType() == 1){
            userDesStr  ="我邀请"+sex+"去："+itme.getPlaceName();
        }
       // String sex = itme.getGender() == 1 ?"他":"她";
        userDes.set(userDesStr);
        ypdBtnVisibility.set(View.VISIBLE);
        statusDes.set(itme.getTimeStr());

        jcpdBtnVisibility.set(View.VISIBLE);



        isVip.set( View.GONE);
        isRenXiang.set(itme.getAvatarVerified() == 0 ? View.GONE : View.VISIBLE);
        isShming.set(itme.getRealNameVerified() == 0 ? View.GONE : View.VISIBLE);


    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });
    //条目的点击事件
    public BindingCommand jsyqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

           // ((AddrDetailVM)viewModel).jieshouyaoqing(uid);
        }
    });


    //条目的点击事件
    public BindingCommand yqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
        //    ((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand jiechuClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserPaifVM)viewModel).jiechupd(uid,UserPaifItemVM.this);
            //   NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });
    //条目的点击事件
    public BindingCommand delyqClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserPaifVM)viewModel).jiechuyaoqing(id,UserPaifItemVM.this);
            // NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand ypdClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            ((UserPaifVM)viewModel).startChat(uid);
          //  NimUIKit.startP2PSession(viewModel.getApplication(), uid);
            //((AddrDetailVM)viewModel).yaoqing(uid);
            // viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    //条目的点击事件
    public BindingCommand imgClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            Bundle bd = new Bundle();
            bd.putString("uid",uid);
            viewModel.startContainerActivity(OthersUserInfoFragment.class.getCanonicalName(),bd);
            //  viewModel.startContainerActivity(SearchFragment.class.getCanonicalName());
        }
    });

    public void updateypd(){
        jsyqBtnVisibility.set(View.GONE);
        ypdBtnVisibility.set(View.VISIBLE);
        statusDes.set("配对于 刚刚");

        jcpdBtnVisibility.set(View.VISIBLE);
        scyqBtnVisibility.set(View.GONE);
    }
}
